
var _LK = {
  primaryData: [],
  thumbnailData: [],
  targetThumbnailData: [],
  hisThumbnailData: [],
  currentData: []
};
var _LL = {
  map: {
    w: 350,
    h: 410
  },
  hasFrozen: false,
  primaryData: [],
  mainDefectList: [], // 渲染当前页面MAP的点数据
  defectGridInfoSelRow: [], //TODO 各种筛选时清空
  defectListGrdRowData: [], //存储glassGrid选中行对象集合
  defectListGridRowNum: 300, // Defect grid 行数
  defectListCurColumnType : 'MIX', // 动态显示隐藏列使用
  isAOI: true,
  sortFlag: false,
  fistFlag: true
};
var rowMaps = {};
// 缩略图 rowMaps
var rowMapt = {};
var pagePoint = 0;
var defaultOptions = {
  tableId: 'defectCodeListGrd',
  mapId: 'mapZone',
  thumbnailId: 'thumbnailZone',
  largeImageId: 'largeImageId',
  layoutId: '',
  thumbnailHeight: 185,
  thumbnailWidth: 185
};
var result = {
  autoCaptureData: [],
  thumbnailHtml: [],
  thumbnailData: [],
  rowMaps: {},
  rowMapst: {}  // 缩略图 rowMaps
};
var loadThumbnail = function (data) {
  $('#thumbnailZone').thumbnail({
    layout: 3, //每行几张
    mode: 'ordinary', //普通 灰阶 修补
    width: 500,  //缩略图宽度
    height: 600, //缩略图高度
    data: data,  //所有缩略图数据 有序Map 排序 eg. --> {key1=value1,key2=value2,key3=value3}
    onClickCell: function (id) {
      var cls = id.replace('_d','_t');
      var arr = $('#defectListPgrid').pqGrid( "getRowsByClass", { cls: cls } );
      //清空之前的选中
      $('#defectListPgrid').pqGrid( "setSelection", null );
      if (arr.length > 0) {
        $('#defectListPgrid').pqGrid( "setSelection", {rowIndx: arr[0].rowIndx} );
      }
    }
  });
};

var pointClick = function (d) {
  var row_id = [d.panel_id, d.defect_no, d.jge_cnt, d.ope_id].join('_');
  $('#thumbnailZone').thumbnail('locate', row_id + '_d');
  if (row_id) {
    var cls = row_id + '_t';
    var arr = $('#defectListPgrid').pqGrid( "getRowsByClass", { cls: cls } );
    //清空之前的选中
    $('#defectListPgrid').pqGrid( "setSelection", null );
    if (arr.length > 0) {
      $('#defectListPgrid').pqGrid( "setSelection", {rowIndx: arr[0].rowIndx} );
    }
    var img = $('#' + row_id + '_d').find('img');
    if (img.length > 0) {
      var path = img[0].src;
      $("#defectPicture").find("img.lazyload").attr("src", "");
      getImageSize(path, function (w, h) {
        $("#defectPicture").find("img.lazyload").attr("src", path);
        $("#defectPicture").find("img.lazyload").attr("onload", "setPictureSize("
            + w + "," + h + ")");
      });
    }
  }
};
var loadMap = function (data, options) {
  var layoutId = options.layoutId;
  _LL.mainDefectList = data;
  options.bigFlg = false;
  if (true === options.isLOI || true === options.isIncludeLOI) {
    var bigFlg = $('input[name=isBig]:checked').val();
    if ('isBig' == bigFlg) {
      options.bigFlg = true
    }
  }
  getMV(options.mapId, layoutId, {
    width: _LL.map.w,
    height: _LL.map.h,
    points: data,
    isATST: options.isATST || '',
    isBig: options.bigFlg,
    // isLOI: false, // 先关闭
    isLOI: options.isLOI || '',
    callback: pointClick
  });
  console.log('loadMap' + options.mapId);
};

var getData = function (data, inspFlg, isAOI, thumbnailData, type) {
  var n, i;
  _LK.tableData = [], thumbnailData = [];
  n = data.length;
  if (type == 'primary') {
    _LK.primaryData = data;
  }
  if (isAOI) {
    for (i = 0; i < n; i++) {
      var obj = data[i];
      if ((obj.auto_capture_flg === 'true'  || obj.shop_id === 'OC') && (inspFlg === ' ' ? true : inspFlg === obj.fbt_flg)) {
        thumbnailData.push(obj);
      }
    }
  } else {
    if (inspFlg === ' '){
      thumbnailData = data;
    } else {
      for (i = 0; i < n; i++) {
        var obj = data[i];
        if (inspFlg === ' ' ? true : inspFlg === obj.fbt_flg) {
          thumbnailData.push(obj);
        }
      }
    }
  }
  return thumbnailData;
};
